﻿using System;
using System.Web;
using Cvk.FAQs;

namespace QueHuongOi.v2010.Manager
{
    public partial class FAQReply : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request["faqid"].ToString()))
                {
                    FAQId = Convert.ToInt32(Request["faqid"].ToString());
                }
                LoadData();
            }
        }
        private int FAQId
        {
            set { ViewState["FAQId"] = value; }
            get
            {
                object o = ViewState["FAQId"];
                if (o != null)
                    return Convert.ToInt32(o.ToString());
                else
                    return 0;
            }
        }
        private void LoadData()
        {
            try
            {
                Cvk_FQA o = FAQBll.claFAQs.GetFQAById(FAQId, Utility.strConnect);
                if (o != null)
                {
                    lblDateCreate.Text = o.CreateDate.Value.ToString("dd/MM/yyyy hh:mm");
                    lblQuestion.Text = o.Question;
                    //ltrQuestion.Text = HttpUtility.HtmlEncode(o.Question);
                    lblSender.Text = o.Name;
                    //lblTitle.Text = o.Title;
                    fckContent.Value = o.Answer;
                    if (o.IsFrequency == true)
                        chkFre.Checked = true;
                    else
                        chkFre.Checked = false;
                    if (o.IsActive == true)
                        chkActive.Checked = true;
                    else
                        chkActive.Checked = false;
                }
            }
            catch { }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Cvk_FQA o = new Cvk_FQA();
                o.IPAddress = Request.UserHostAddress;
                o.Answer = fckContent.Value;
                o.AnswerDate = DateTime.Now;
                o.IsActive = chkActive.Checked;
                o.IsFrequency = chkFre.Checked;
                o.FQAId = FAQId;
                FAQBll.claFAQs.Update(o, Utility.strConnect);
                lblStatus.Text = "Lưu thành công.";
            }
            catch { lblStatus.Text = "Lưu thất bại."; }
        }
    }
}